Strict
Import mojo
Import agfx

Class TEdge

	Field A:TVector2
	Field B:TVector2
	Field length:Float
	Field dir:TVector2
	Field center:TVector2
	Field normal:TVector2
	
	
	Method New()
		Self.A			= New TVector2()
		Self.B			= New TVector2()
		Self.length		= 0
		Self.dir		= New TVector2()
		Self.center		= New TVector2()
		Self.normal		= New TVector2()
	End Method
	
	Method Update:Void()
		Self.length = VecDist(Self.B,Self.A)
		Self.dir = VecNormalize(VecSub(Self.B,Self.A))
		Self.center = VecAdd(Self.A,VecMult(Self.dir,Self.length*0.5))
		Self.normal = VecLeftNormal(Self.dir)
		
	End Method

	
	Method DebugDraw_Edge:Void()	
		SetColor(0,255,0)
		DrawLine(Self.A.x,Self.A.y,Self.B.x,Self.B.y)
	End Method
	
	Method DebugDraw_EdgeCenter:Void()	
		SetColor(255,255,0)
		DrawOval(Self.center.x-2,Self.center.y-2,4,4)
	End Method
	
	Method DebugDraw_EdgeNormal:Void()	
		SetColor(255,255,0)
		Local nB:TVector2 = New TVector2(Self.center.x+Self.normal.x*16,Self.center.y+Self.normal.y*16)		
		DrawLine(Self.center.x,Self.center.y,nB.x,nB.y)
	End Method
	
End Class